package top.xiaoshuaila.moments.service;

import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import top.xiaoshuaila.moments.mapper.DetailMapper;
import top.xiaoshuaila.moments.pojo.Dynamic;
import top.xiaoshuaila.moments.pojo.Zaner;
import top.xiaoshuaila.moments.utils.Usersutils;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

@Service
public class DetailServiceImpl implements DetailService {
    @Autowired
    private DetailMapper detailMapper;
    @Override
    public Dynamic getdetail(long dyid, long userid) {

        return detailMapper.getdetail(dyid,userid);
    }

    @Override
    public boolean getself(long dyid, long userid) {
        boolean isself=detailMapper.isself(dyid,userid);
        if(isself)
            detailMapper.removeself(dyid,userid);
        else detailMapper.setself(dyid,userid);
        return !isself;
    }

    @Override
    public boolean deletedy(long dyid, long userid, boolean iszhuan) {
        System.out.println(dyid+":"+userid+":"+iszhuan);
        if(iszhuan)
        {
            detailMapper.deletezhuanzan(dyid,userid);
            detailMapper.deletezhuandy(dyid,userid);
        }
        else {
            detailMapper.deletezan(dyid,userid);
            detailMapper.deletedy(dyid,userid);
            detailMapper.deletezhuan(dyid,userid);
        }
        return true;
    }

    @Override
    public List<Zaner> getzaner(long dyid, long id,int page) {
        return detailMapper.getzaner(dyid,id,page*5,5);
    }
}
